<?php
/**
 * Created by PhpStorm.
 * User: Monkey
 * Date: 2021/10/13
 * Time: 11:27
 * Desc: 登陆
 */

namespace app\backend\validate;

use think\Validate;

class AdminValidate extends Validate
{
    protected $rule = [
        'page' => 'integer',
        'limit' => 'integer',
        'account' => 'require|regex:/^[a-zA-Z0-9_\.@]{6,30}$/',
        'nickname' => 'require|max:30',
        'role_id' => 'require|integer',
        'status' => 'require|in:0,1',
        'oldPsw' => 'require',
        'newPsw' => 'require|regex:/^[a-zA-Z0-9@]{6,30}$/',
        'rePsw' => 'require|confirm:newPsw',
        'password' => 'require|regex:/^[a-zA-Z0-9]{6,30}$/'
    ];

    protected $message = [
        'page.integer' => '页码格式错误',
        'limit.integer' => '条数格式错误',
        'account.require' => '账号不能为空',
        'account.regex' => '账号格式错误(a-zA-Z0-9._@组合),6-30个字符',
        'nickname.require' => '昵称不能为空',
        'nickname.max' => '昵称最多30个字符',
        'role_id.require' => '角色不能为空',
        'role_id.integer' => '角色格式错误',
        'status.require' => '状态不能为空',
        'status.in' => '状态格式错误',
        'oldPsw.require' => '旧密码不能为空',
        'newPsw.require' => '新密码不能为空',
        'newPsw.regex' => '密码格式错误(a-zA-Z0-9组合),6-30个字符',
        'rePsw.require' => '确认密码不能为空',
        'rePsw.confirm' => '两次密码不一致',
        'password.require' => '密码不能为空',
        'password.regex' => '密码格式由(a-zA-Z0-9)组成,6-30个字符',
    ];

    protected $scene = [
        'index'  =>  ['page','limit'],
        'add' => ['account','nickname','role_id'],
        'edit' => ['id','account','nickname','role_id'],
        'del' => ['id'],
        'editStatus' => ['id','status'],
        'editPassword' => ['oldPsw','newPsw','rePsw'],
        'resetPassword' => ['id','password']
    ];
}
